<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
<title>管理操作员</title>
<%@ include file="../common/base.jsp" %>
</head>

<body id="body">
<!--head-->
<div id="head">
	<%@ include file="../common/head.jsp" %>
</div>
<!--head end-->
<!--container-->
<div id="container">
	<div id="pageId" style="display: none;">02-06-01</div>
		<!--sidebar-->
		<%@ include file="../common/menu.jsp" %>
	    <!--sidebar-->
    <!--main-->
    <div class="main">
    	<div class="location" style="background-position:22px -109px;">
        	平台管理<span>&gt;</span>订单管理<span>&gt;</span>订单信息管理
        </div>
        <!--content-->
        <div class="content">
			<div class="info_container">
				<i style="display:inline-block;">
					<label style="width:210px;text-align:right;min-width:200px;margin-right:6px;" >订单类型：
						<div class="requery_box">
							<select id="orderState" name="orderState" style="width: 120px;">
								<option value="-1">全部</option>
								<c:forEach var="item" items="${dictList}" varStatus="vatS">
									<option value="${item.enumCode}">${item.enumName}</option>
								</c:forEach>
							</select>
						</div>
					</label>
				</i>
				<label style="width: 450px" >
					<i class="sel_date">时间选择：</i>
					<input type="text" id="startTime" class="Wdate"
						   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'});this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"
						   value="${startTime}"
						   readonly/>
					—
					<input type="text" id="endTime" class="Wdate"
						   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'});this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"
						   value="${endTime}"
						   readonly/>
				</label>
				<button type="button" class="btn btn_search" id="query_button"></button>
			</div>
            <div id="tableResult">
            	<table class="table_type1">
	                <thead>
	                    <tr>
	                        <th>序号</th>
	                        <th>产品名称</th>
	                        <th>订单价格</th>
	                        <th>提交订单名称</th>
	                        <th>订单状态</th>
	                        <th>订单创建时间</th>
	                        <th>操作</th>
	                    </tr>
	                </thead>
	                <tbody id="bodyResult"></tbody>
	            </table>
            </div>
            <div class="page">
                	<div class="itemNum" >
		                    	显示：<select id="selItem">
		                    			<option selected="selected" id="20">20</option>
		                    			<option id="30">30</option>
		                    			<option id="40">40</option>
		                    			<option id="50">50</option>
		                    		</select>条，共 <a id="totalCount" onclick="javascript:void(0);" ></a> 条
		            </div>
                    <ul class="pagination" id="pageCur"></ul>
            </div>
        </div>
        <!--content-->

		<!--遮罩层-->
		<div id="mask" style="display:none;"></div>
		<!--遮罩层-->
		<!--弹出框-->
		<div id="popBox" class="popBox2" style="display:none;">
			<h2></h2>
			<a href="javascript:;" class="close" onClick="closeHide();"></a>
			<div id="popBox_con1" style="display:none;">
				<div class="pop_content" style="height: 240px;">
					<ul class="recharge_list tzz_list pop_list" style="width:60%">
						<li class="tzz_code" style="height:auto;">
							<label style="width:28%;">订单是否退款：</label>
							<input type="radio" name="radioState" checked value="6">否
							<input type="radio" name="radioState" value="7">是
						</li>
						<li style="height:auto;">
							<label style="width:28%;">退款原因：</label>
							<textarea id="cause" name="cause" rows="5" style="width: 250px; height: 140px;"></textarea>
						</li>
					</ul>
				</div>
				<div class="pop_button">
					<a href="javascript:;" onClick="orderRefund();">提交</a>
					<a href="javascript:;" onClick="closeHide();">关闭</a>
				</div>
			</div>
    	</div>
		<!--foot-->
		<%@ include file="../common/foot.jsp" %>
		<!--foot-->
    <!--main-->
</div>
<!--container-->
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
<script type="text/javascript">
	var orderId = 0;
    var Ocon1=document.getElementById('popBox_con1');
    var Omask=document.getElementById('mask');
    var OpopBox=document.getElementById('popBox');
    function approval(id){
        Omask.style.display='block';
        OpopBox.style.display='block';
        Ocon1.style.display='block';
        orderId = id;
    }

    function closeHide(){
		$("#cause").text("");
        $("#popBox").hide();
        $("#mask").hide();
    }

    function orderRefund(){

        var orderRefundDesc = $("#cause").val();
        var orderState = $("input[name='radioState']:checked").val();
        $.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath}/order/updateOrderState",
            dataType:"json",
            data: {
                "id":orderId,
                "orderState":orderState,
                "orderContent":orderRefundDesc
            },
            success: function(data){
                if (data.errorCode==0) {
                    closeHide();
                    prompt.alert("线下退款已成功，订单关闭！");
                    setTimeout(function(){
                        loadResult(1,$("#selItem").val());
                    },2000);
                }else{
                    prompt.alert(data.msg);
                }
            }
        });

    }





//加载ajax请求
function loadResult(page,numPerPage){
	loadResultPerfect(page,numPerPage,"order/queryOrderDate",retParam());
}

// 加载ajax返回结果
function loadTableResult(data){
	var jo = data.json;
	if(jo != '' && jo != null){
		for (var i = 0; i < jo.length; i++) {
		    var opHtml = "<a href='order/showOrderDetail?id=" + jo[i].id + "'>订单详情</a>&nbsp;";
		    var orderState = jo[i].orderState;if(orderState == 6){
                opHtml = opHtml+"<a href='javascript:void(0);'  onclick = 'approval("+ jo[i].id + ")'>退款</a>";
			}



			var content = "<tr>"+
	                    	"<td>"+(i+1)+"</td>" +
							"<td>"+jo[i].productName+"</td>" +
                			"<td>"+jo[i].orderMoney+"</td>" +
							"<td>"+jo[i].nickName+"</td>" +
							"<td>"+jo[i].orderName+"</td>" +
							"<td>"+dateFormatTimeLong(jo[i].createTime)+"</td>" +
	                    	"<td>"+opHtml+"</td>"+
	                      "</tr>";
	        $("#bodyResult").append(content);
	    }
	}
}

function del(id){
	
	prompt.confirm("您确定要下架该产品吗?",function(){
			$.ajax({
			   type: "POST",
			   url: "${pageContext.request.contextPath}/aiche/deleteProduct",
			   dataType:"json",
			   data: {
				   id:id
			   },
			   success: function(data){
			   		prompt.alert(data.msg);
					if (data.errorCode==0) {
						loadResult(1,$("#selItem").val());
					}
			   }
		});
	});
}

function resetPwd(operatorId,loginName){
	prompt.confirm("您确定要重置密码吗?",function(){
			$.ajax({
			   type: "POST",
			   url: "${pageContext.request.contextPath}/operatorManagement/resetPwd",
			   dataType:"json",
			   data: {
				   operatorId:operatorId,
				   loginName:loginName
			   },
			   success: function(data){
			   		prompt.alert(data.msg);
					if (data.errorCode==0) {
						loadResult(1,$("#selItem").val());
					}
			   }
		});	
	});
}

function addSubmit(){
	window.location.href = "${pageContext.request.contextPath}/aiche/showSaveOrUpdateProduct?type=save";
}

function retParam(){
    var param =  "startTime=" + $("#startTime").val() +
        "&endTime=" + $("#endTime").val() +
        "&orderState=" + $("#orderState").val();
    return param;
}

//表格排序表头样式
$(document).ready(function(e) {
	loadResult(1,$("#selItem").val());
});

</script>
</body>
</html>